/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upn.sigemfi.rec.bc;

import edu.upn.sigemfi.sac.bc.SolicitudCreditoFacadeLocal;
import edu.upn.sigemfi.sac.be.SolicitudCredito;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Diego
 */
public class SolicitudCreditoDelegate {

    private SolicitudCreditoFacadeLocal local;

    public SolicitudCreditoDelegate() {
        local = lookupSolicitudCreditoFacade();
    }


    public SolicitudCredito buscar(long credito) throws Exception{
        try{
            return local.buscarPorNroCredito(credito);
        }
        catch(Exception ex){
            local=lookupSolicitudCreditoFacade();
            throw new Exception("Buscar Solicitud Creidto"+ex.getMessage());
        }
    }

    private SolicitudCreditoFacadeLocal lookupSolicitudCreditoFacade() {
        try {
            Context c = new InitialContext();
            return (SolicitudCreditoFacadeLocal) c.lookup("java:comp/env/SolicitudCreditoFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
